package business.cdss;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.Yaml;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;
import utils.YamlReadUtil;

import java.io.FileNotFoundException;

import static common.Login.login;

public class GetPatientList {
    Logger log = Logger.getLogger(GetPatientList.class);
    public static final String system = "env.properties";
    Data data = login();

    public JSONArray getlist() throws ConfigurationException, FileNotFoundException, YamlException {

        String path = new GetFileMess().getValue("CDSSPath", system);
        Yaml yaml = YamlReadUtil.getLocatorMap(path, this.getClass().getName());
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("userId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("org_ids", "true");
        json.put("startDate", "");
        json.put("endDate", "");
        json.put("page", "1");
        json.put("size", "10");
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "get", yaml.getUri());
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);
        JSONObject obj = JSON.parseObject(jsonStr);
        JSONObject jsonObject = obj.getJSONObject("responseData");
        JSONArray contentArr = jsonObject.getJSONArray("content");
        return contentArr;
    }


    public static void main(String[] args) throws FileNotFoundException, ConfigurationException, YamlException {

        GetPatientList getPatientList = new GetPatientList();
        JSONArray contentArr = getPatientList.getlist();
        contentArr.get(0);
    }


}
